Page({
  data: {
    scale: 12,
    latitude: 36,
    longitude: 120
  },
  onReady() {
    this.mapCtx = wx.createMapContext('myMap')
    this.getMyLocation()
  },
  async getMyLocation() {
    const res = await wx.getLocation({ type: 'wgs84' })
    this.setData({
      latitude: res.latitude,
      longitude: res.longitude,
    })
  },
  getCenterLocation(){
  },
  changeView(e) {
    let item = e.currentTarget.dataset.bean;
    let num = item == 1 ? 1 : -1;
    num = this.data.scale + num
    if (4 < num && num < 19) {
      this.mapCtx.getCenterLocation({
        success: res => {
          this.setData({
            latitude: res.latitude,
            longitude: res.longitude,
            scale: num
          })
        }
      })
    }
  }
})
